package com.itqn.servlet;

import com.alibaba.fastjson.JSONArray;
import com.itqn.pojo.Product;
import com.itqn.service.Impl.ProductServiceImpl;
import com.itqn.service.ProductService;
import lombok.SneakyThrows;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(value = "/productEchoServlet")
public class ProductEchoServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @SneakyThrows
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //解决中文乱码问题
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html; charset=UTF-8");

        //获取参数
        String id = request.getParameter("id");
        //创建业务逻辑层对象
        ProductService productService=new ProductServiceImpl();
        Product product = productService.findById(Integer.valueOf(id));
        request.setAttribute("product",product);
        request.getRequestDispatcher("/admin/product/update.jsp").forward(request,response);

    }
}
